package com.atguigu.crowd.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atguigu.crowd.entity.Menu;
import com.atguigu.crowd.entity.MenuExample;
import com.atguigu.crowd.mapper.MenuMapper;
import com.atguigu.crowd.service.api.MenuService;

@Service
public class MenuServiceImpl implements MenuService {

	@Autowired
	private MenuMapper menuMapper;

	@Override
	public List<Menu> getAll() {
		// 1.根据登录账号查询Admin对象
		// ①创建AdminExample对象
		MenuExample menuExample = new MenuExample();

		// ④调用adminMapper的方法执行查询
		List<Menu> list = menuMapper.selectByExample(menuExample);

		return list;
	}

	@Override
	public void saveMenu(Menu menu) {
		menuMapper.insert(menu);
	}

	@Override
	public void updateMenu(Menu menu) {
		
		// 由于 pid 没有传入，一定要使用有选择的更新，保证“pid”字段不会被置空 
		menuMapper.updateByPrimaryKeySelective(menu);
		
	}

	@Override
	public void removeMenu(Integer id) {
		menuMapper.deleteByPrimaryKey(id); 

	}
}
